package com.by.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;


/**
 * @author LittleDesire
 * @description
 * @date 2022-03-23 周三 9:10
 * @since 17
 */
@Configuration
@PropertySource("classpath:druid.properties")
public class DruidConfig {

    @Value("${druid.url}")
    private String url;
    @Value("${druid.username}")
    private String userName;
    @Value("${druid.password}")
    private String password;
    @Bean(initMethod = "init",destroyMethod = "close")
    public DruidDataSource dds() {
        DruidDataSource dds = new DruidDataSource();
        dds.setUrl("jdbc:mysql://localhost:3306/db");
        dds.setUsername("root");
        dds.setPassword("123");
        return dds;
    }
    @Bean(initMethod = "init",destroyMethod = "close")
    public DruidDataSource dds2() {
        DruidDataSource dds = new DruidDataSource();
        dds.setUrl(url);
        dds.setUsername(userName);
        dds.setPassword(password);
        return dds;
    }

    @Bean
    public QueryRunner run() {
        return new QueryRunner(dds2());
    }
}
